package com.lagou.utils;

import com.lagou.annotation.Autowired;
import com.lagou.annotation.Service;

import java.sql.SQLException;

/**
 * @author: lcz
 * @date: Created in 14:54 2020/10/5
 * @description:
 */
@Service
public class TransactionManager {
    @Autowired
    private ConnectionUtils connectionUtils;

    /**
     * @author: lcz
     * @date: Created in 14:56 2020/10/5
     * @description: 提交事务
     */
    public void begin() throws SQLException {
        connectionUtils.getCurrentThreadConn().setAutoCommit(false);
    }

    /**
     * @author: lcz
     * @date: Created in 14:56 2020/10/5
     * @description: 提交事务
     */
    public void commit() throws SQLException {
        connectionUtils.getCurrentThreadConn().commit();
    }

    /**
     * @author: lcz
     * @date: Created in 14:57 2020/10/5
     * @description: 回滚事务
     */
    public void rollback() throws SQLException {
        connectionUtils.getCurrentThreadConn().rollback();
    }
}
